$(function () {
    getList();
    try {
        CSharpFunction.ShowToolbar();
    } catch (e) {
    }
});

function getList() {
    $.ajax({
        type: 'get',
        url: '/Examiner/GetSubjectList?token=' + _token,
        success: function (res) {
            if (res.code < 0) {
                alert('系统异常，请尝试重新登录！');
                window.location.href = '/Examinee/Login';
                return;
            }

            var headerContent = '<div class="tab"><div class="item cur">考试</div></div>';
            $('.examlist').html(headerContent);
            if (res.payload.length <= 0) {
                $('.examlist').append('<h3 style="text-align: center; padding-top: 15px;"><img src="/App/images/nodata.jpg"/></h3>');
                return;
            }
            for (var i = 0; i < res.payload.length; i++) {
                var buttonName = res.payload[i].sysState == 2 ? '继续答题' : '开始考试';
                var showName = res.payload[i].sysState == 2 ? '进行中' : '未作答';
                $('.examlist').append('' +
                    '<div class="tabcon">' +
                    '   <div class="examitem">' +
                    '       <div class="examlink">' +
                    '           <button type="button" class="btn-3" onclick="start(\'' + res.payload[i].examSubjectID + '\')">' + buttonName + '</button>' +
                    '       </div>' +
                    '       <div class="title">' +
                    '           <span class="tdetail">' + res.payload[i].examSubjectName + '</span>' +
                    '           <span class="mark" style="text-indent:8px;">' + showName + '</span>' +
                    '           <span style="margin-left:250px;font-size:20px;color:#333;text-indent:8px;">' + res.payload[i].appName + '</span>' +
                    '       </div>' +
                    '   </div>' +
                    '</div>');
            }
        }
    });
}

function start(subjectId) {
    $.ajax({
        type: 'post',
        url: '/Examiner/GetExamInfo',
        data: {
            token: _token,
            subjectID: subjectId
        },
        success: function (res) {
            if (res.code >= 0) {
                window.location.href = '/Examiner/DownloadPaper?token=' + _token;
            } else {
                alert(res.message);
                window.location.href = '/Examinee/Login';
            }
        }
    });
}